//
//  PoiSearchDetailViewController.m
//  wtshoppingcite
//
//  Created by TW on 15-3-20.
//  Copyright (c) 2015年 TW. All rights reserved.
//

#import "PoiSearchDetailViewController.h"

@interface PoiSearchDetailViewController ()<UIWebViewDelegate>

@property(strong,nonatomic)BMKPoiDetailSearchOption *citySearchOption;
@property(nonatomic,strong)UIWebView *webView;
@property(nonatomic,strong)NSString *urlString;
@property(nonatomic,strong)UIActivityIndicatorView *activityIndicator;

@end

@implementation PoiSearchDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _poisearch = [[BMKPoiSearch alloc]init];
    _citySearchOption = [[BMKPoiDetailSearchOption alloc]init];
    _citySearchOption.poiUid = self.uid;
    BOOL flag = [_poisearch poiDetailSearch:_citySearchOption];
    if(flag)
    {
        
        NSLog(@"详情检索信息成功");
    }
    else
    {
        
        NSLog(@"详情检索信息失败");
    }
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 480)];
    [self.view addSubview:_webView];
    
    if (!IS_4_INCH_SCREEN) {
        _webView.height = 480-64;
    }else{
        _webView.height = 480+22;
    }
    
    [_webView setUserInteractionEnabled:YES];  //是否支持交互
    [_webView setDelegate: self];     //委托
    [self.view addSubview:_webView];
    
    
    _activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(10,10,20,20)];//需要在.h文件中进行声明
    
    [_activityIndicator setCenter:self.view. center];//位置
    
    [_activityIndicator   setActivityIndicatorViewStyle: UIActivityIndicatorViewStyleGray];//颜色根据不同的界面自己调整
    
    [self.view  addSubview:_activityIndicator];

    
    // Do any additional setup after loading the view.
}

#pragma mark  返回POI详情搜索结果
- (void)onGetPoiDetailResult:(BMKPoiSearch*)searcher result:(BMKPoiDetailResult*)poiDetailResult errorCode:(BMKSearchErrorCode)errorCode{
    
    NSLog(@"%@",poiDetailResult);
    if (errorCode == BMK_SEARCH_NO_ERROR) {
        [self setPoiUrlString:poiDetailResult.detailUrl];
        
    } else if (errorCode == BMK_SEARCH_AMBIGUOUS_ROURE_ADDR){
        NSLog(@"起始点有歧义");
    } else {
        // 各种情况的判断。。。
    }

}

-(void)setPoiUrlString:(NSString *)url{
    
    NSURL *urlString = [NSURL URLWithString:url];
    NSURLRequest *request = [NSURLRequest requestWithURL:urlString];
    [_webView loadRequest:request];
    

}

#pragma mark - webview
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    
    _webView.hidden = NO;
    [_activityIndicator stopAnimating];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    
    [_activityIndicator stopAnimating];
    //    [self showHUDWithString:@"网络错误！"];
    
    NSLog(@"error :%@",error);
    
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [_activityIndicator startAnimating];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)viewWillAppear:(BOOL)animated {
    [_mapView viewWillAppear];
    _mapView.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
    _poisearch.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
    ;
    
}

-(void)viewWillDisappear:(BOOL)animated {
    [_mapView viewWillDisappear];
    _mapView.delegate = nil; // 不用时，置nil
    _poisearch.delegate = nil; // 不用时，置nil
    
}




@end
